package com.example.home.government.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.government.acivity.PersonDetails;
import com.example.home.government.bean.DetailsBean;

import java.util.List;

import static com.example.home.tool.StaticActi.ip;

public class AppealMainAdapter extends RecyclerView.Adapter<AppealMainAdapter.MyHoldy> {
    private Context context;
    private List<DetailsBean.RowsBean> list;

    public AppealMainAdapter(Context context, List<DetailsBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_general,null);
        return new MyHoldy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHoldy holder, int position) {
        Glide.with(context).load(ip + list.get(position).getImgUrl()).into(holder.cover);
        holder.title.setText(list.get(position).getTitle());
        holder.content.setText(list.get(position).getUndertaker());
        String sta = list.get(position).getState();
        if ("0".equals(sta)){
            holder.contentNum.setText("未处理");
        }else if ("1".equals(sta)){
            holder.contentNum.setText("已处理");
        }
        holder.time.setText(list.get(position).getCreateTime());
        holder.rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PersonDetails.class);
                intent.putExtra("person",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class MyHoldy extends RecyclerView.ViewHolder {
        private RelativeLayout rootView;
        private ImageView cover;
        private TextView title;
        private TextView content;
        private TextView contentNum;
        private TextView time;
        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            rootView = itemView.findViewById(R.id.rootView);
            cover = itemView.findViewById(R.id.cover);
            title = itemView.findViewById(R.id.title);
            content = itemView.findViewById(R.id.content);
            contentNum = itemView.findViewById(R.id.contentNum);
            time = itemView.findViewById(R.id.time);


        }
    }
}
